package com.application.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestParam;

import com.application.bean.PageContion;
import com.application.dao.JpaDao;
import com.application.mybatis.UserMybatis;
import com.application.pojo.Auth;
import com.application.pojo.MenuMessage;
import com.application.pojo.OrderMessage;
import com.application.pojo.User;
import com.application.pojo.student;
import com.github.pagehelper.PageHelper;

@Service
public class Bsm {
//	@Autowired
//	JavaMailSenderImpl mail;
	@Autowired
	UserMybatis u;
	@Autowired
	JpaDao JpaDao;
	@Autowired
	JdbcTemplate t;
	@Transactional(transactionManager="datasourceTransAction")
	public void saveUser(Map<String, String> map) {
//		JpaDao.saveAndFlush(u);
//		MimeMessage m = mail.createMimeMessage();
//		MimeMessageHelper helper = new MimeMessageHelper(m);
//		Configuration c = new Configuration(Configuration.VERSION_2_3_23);
//		c.setClassForTemplateLoading(resourceLoaderClass, basePackagePath);
//		Template template = c.getTemplate("").
//		FreeMarkerTemplateUtils.processTemplateIntoString(template, model)
		u.insertUser(map);
	}
	@Transactional(transactionManager="datasourceTransAction")
	public List<OrderMessage> select(){
		return u.selectOrder();
	}
	@Transactional(transactionManager="datasourceTransAction")
	public int countStudent(){
		return u.countStudent();
	}
	@Transactional(transactionManager="datasourceTransAction")
	public int countStudentBoy(){
		return u.countStudentBoy();
	}
	@Transactional(transactionManager="datasourceTransAction")
	public int countStudentGirl(){
		return u.countStudentGirl();
	}
	@Transactional(transactionManager="datasourceTransAction")
	public List<student> selectStudent(PageContion pageContion){
		PageHelper.startPage(pageContion.getPageIndex()+1, pageContion.getLimit());
		return u.selectStudent();
	}
	@Transactional(transactionManager="datasourceTransAction")
	public boolean saveStudent(student s){
		return u.saveStudent(s)!=0?true:false;
	}
	@Transactional(transactionManager="datasourceTransAction")
	public boolean delStudent(Integer id){
		return u.delStudent(id)!=0?true:false;
	}
	@Transactional(transactionManager="datasourceTransAction")
	public boolean editStudent(student s){
		return u.editStudent(s)!=0?true:false;
	}
	@Transactional(transactionManager="datasourceTransAction")
	public String del(@RequestParam("id")Long id){
		u.delOrder(id);
		return "success";
	}
	@Transactional(transactionManager="datasourceTransAction")
	public void insertModel(Auth auth){
		u.insertModel(auth);
	}
	@Transactional(transactionManager="datasourceTransAction")
	public boolean exitModel(Auth auth){
		return u.selectModel(auth)!=0?false:true;
	}
	@Transactional(transactionManager="datasourceTransAction")
	public boolean exitMenu(String menuId){
		return u.exitMenu(menuId)==0?true:false;
	}
	@Transactional(transactionManager="datasourceTransAction")
	public User selectUserByName(String name){
		return u.selectUserByName(name);
	}
	@Transactional(transactionManager="datasourceTransAction")
	public User updateUserByName(User name){
		return u.updateUserByName(name);
	}
	@Transactional(transactionManager="datasourceTransAction")
	public student selectStudentById(int id){
		return u.selectStudentById(id);
	}
	@Transactional(transactionManager="datasourceTransAction")
	public int saveMenu(MenuMessage menuMessage){
		return u.saveMenu(menuMessage);
	}
	@Transactional(transactionManager="datasourceTransAction")
	public List<MenuMessage> selectRoorMenu(){
		return u.selectRootMenu();
	}
	@Transactional(transactionManager="datasourceTransAction")
	public List<MenuMessage> selectSubMenu(String parentId){
		return u.selectSubMenu(parentId);
	}
}
